<script setup>
import PostListItemImage from '@/components/postListItemImage.vue'
import { getTimeStr } from '@/utils/transIUtils'
import { useRouter, useRoute } from 'vue-router'
const router = useRouter()
const route = useRoute()
const props = defineProps({
  data: {
    type: Object,
    required: true,
  },
})

const handleClick = () => {
  // 如果路径有post,则去掉post及其后面的内容，否则直接添加post/id
  const path = route.path.replace(/\/post.*/, '')
  router.push(`/home/post/${props.data.id}`)
}
</script>

<template>
  <div
    @click="handleClick()"
    class="border-1 border-solid border-[--line-1] flex-1 rounded-md p-2 flex gap-2 hover:bg-[--fill-1] cursor-pointer min-w-[250px]">
    <PostListItemImage :type="data.type" :media="data.media" isTopPost />

    <div class="flex flex-col justify-between">
      <div class="text-sm font-semibold">{{ data.title }}</div>
      <!-- <div>
        <img :src="data.user.avatar" alt="" class="w-4 h-4 rounded-full">
        <div>{{ data.user.name }}</div>
      </div> -->
      <div class="text-sm text-slate-500">{{ getTimeStr(data.createTime) }}</div>
    </div>
  </div>
</template>
